package com.wc.alorithm_blue_bridge.线段树.区间选数k;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/18 8:01
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3440219&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 正常是要使用ST表的
     * 但是习惯使用线段树了
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, M = N << 2;
    static int[] maxv = new int[M], minv = new int[M];
    static int[] a = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        build(1, 1, n);
        long mx = 0, mn = 0;
        while (m-- > 0) {
            int l = sc.nextInt(), r = sc.nextInt();
            int[] t = query(1, 1, n, l, r);
            mx += t[0];
            mn += t[1];
        }
        out.println(mn + " " + mx);
        out.flush();
    }

    static void build(int u, int l, int r){
        if (l == r) {
            maxv[u] = minv[u] = a[l];
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static int[] query(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) return new int[]{maxv[u], minv[u]};

        int mid = l + r >> 1;
        if (qr <= mid) return query(u << 1, l, mid, ql, qr);
        if (ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
        int[] L = query(u << 1, l, mid, ql, mid);
        int[] R = query(u << 1 | 1, mid + 1, r, mid + 1, qr);
        int mx = Math.max(L[0], R[0]), mn = Math.min(L[1], R[1]);
        return new int[]{mx, mn};
    }

    static void pushUp(int u) {
        maxv[u] = Math.max(maxv[u << 1], maxv[u << 1 | 1]);
        minv[u] = Math.min(minv[u << 1], minv[u << 1 | 1]);
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
